<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>todoList</title>
    <!-- 
         编程思想:
            1. 点击添加按钮，获取输入框内容，添加到列表显示
            2. 点击删除按钮，根据索引号删除数组中指定元素  list.splice(0,1)
    -->
</head>
<body>
    <div id="root">
        <!-- 动态渲染 -->
    </div>

    <script src="./lib/vue.global.js"></script>

    <script>
        // vue组件，有特定选项的javascript对象
        const root = {
            data() {
                return {
                    inputValue:'',
                    list:['javascript']  //  list.splice(0,1)
                }
            },
            /*html*/
            template: `
                <div>
                    <input name="inputValue" placeholder="请输入内容" v-model="inputValue"/>
                    <button @click="bindAdd">添加</button>    
                    <ul>
                       <li v-for="(item,index) in list" :key="index">{{item}} <button @click="bindDelete(index)">删除</button></li>   
                    </ul>
                </div>
            `,
            methods:{
                bindAdd(){
                    //获取输入框内容
                    const inputValue = this.inputValue
                    this.list.push(inputValue)
                    this.inputValue = ''
                },
                bindDelete(index){
                    this.list.splice(index,1)
                }
            }
        }
        const app = Vue.createApp(root)
        
        app.mount('#root')
        

    </script>
</body>
</html>